

const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    faver: [],
    moreshow: false,
    moretit: true,
    issc: '收藏',
    list: [],
    job: [],
    jobList: [],
    id: '',
    isClick: false,
    jobStorage: [],
    jobId: '',
    collectNum: 0
  },
  go_jobInfo: function (t) {
    var z = t.currentTarget.dataset.zdy,
      a = t.currentTarget.dataset.index,
      i = this.data.list;
    i[a].zwk_jishu++, this.setData({
      list: i
    }), wx.navigateTo({
      url: "../search/jobInfo/jobInfo?zdy=" + z 
    });
  },
 
  clear_collect: function () {
    wx.setStorageSync("collectNum", 0), this.setData({
      collectNum: wx.getStorageSync("collectNum")
    }), wx.navigateTo({
      url: "../search/myJob/myJob"
    });
  },
  addJob: function (t) {
    var _ = this,
      i = t.currentTarget.dataset.id,
      s = this.data.list,
      o = t.currentTarget.dataset.index;
     console.log(s[o])
      wx.request({
        url: 'https://zg99.offcn.com/index/chaxun/writelogs?actid=51488&callback=?',
        data: {
          phone: wx.getStorageSync('51488phone'),
          nf:s[o].nianfen,
          zwmc:s[o].zhiweimingcheng,
          bmmc:s[o].zhaolujiguan,
          zlsl:s[o].luyongjihua,
          msbl:s[o].wuritongguo,
          zzmm:s[o].zhengzhimianmao,
          bz:s[o].beizhu,
          zwdm:s[o].zhiweidaima,
          zdy:i,
          sstimes: new Date().getTime(),
        },
        success(res) {
          var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
          console.log(theJson);
          if (theJson.status == 1) {
            wx.showToast({
              title: '添加成功！',
              icon: 'none',
              duration: 2000
            })
          } else {
            wx.showToast({
              title: '请勿重复添加！',
              icon: 'none',
              duration: 2000
            })
          }
        }
      })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log(wx.getStorageSync('theJson'));
    let theJson = wx.getStorageSync('theJson')
    that.setData({
      list: theJson
    })
    console.log(that.data.list)
  },
  clase: function (e) {
    let that = this
    let index = 0;
    let array = this.data.list; //获取循环数组对象
    for (let item of array) {
      //如果当前点击的对象id和循环对象里的id一致
      if (item.id == e.currentTarget.dataset.id) {
        //判断当前对象中的insert是否为true（true为显示，其他为隐藏） insert是新增的一个值然后进行判断
        if (array[index].insert == "" || array[index].insert == undefined) {
          array[index].insert = "true";
        } else {
          array[index].insert = "";
        }
      }
      index++;
    }
    //将数据动态绑定 
    that.setData({
      list: array
    })
  },
  gofav: function () {
    db.collection('userInfo').where({
      _openid: app.globalData.openid,
    }).get({
      success: function (res) {
        console.log(res.data[0].fav)
        var arry1 = res.data[0].fav;
        for (var i = 0; i < arry1.length; i++) {
          for (var j = i + 1; j < arry1.length; j++) {
            if (arry1[i].id == arry1[j].id) { //第一个等同于第二个，splice方法删除第二个
              arry1.splice(j, 1);
              j--;
            }
          }
        }
        console.log(arry1)
        db.collection('userInfo').where({
          _openid: app.globalData.openid,
        }).update({
          data: {
            fav: arry1
          }
        })
      }
    })
    wx.navigateTo({
      url: "/pages/fav/fav"
    });
  },
  more: function () {
    var that = this;
    var moreshow = that.data.moreshow;
    var moretit;
    if (that.data.moretit == '查看更多') {
      that.setData({
        moretit: '收起'
      })
    } else {
      that.setData({
        moretit: '查看更多'
      })
    }
    that.setData({
      moreshow: !that.data.moreshow
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

   /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
      var area = wx.getStorageSync('area')
      var agent = wx.getStorageSync('agent')
      var page = wx.getStorageSync('page')
      return {
          title: '2021国家公务员招录考试职位表',
          path: 'pages/search/search/search?area=' + area + '&agent=' + agent + '&page=' + page
      }
  },
  /**分享到朋友圈*/
  onShareTimeline: function () {
      var area = wx.getStorageSync('area')
      var agent = wx.getStorageSync('agent')
      var page = wx.getStorageSync('page')
      return {
          title: '2021国家公务员招录考试职位表',
          path: 'pages/search/search/search?area=' + area + '&agent=' + agent + '&page=' + page
      }
  }
})